<template>
  <div class="warp-box">
    <el-row class="search-box" :gutter="10">
      <el-col :span="20">
        <el-input
          style="width:200px"
          v-model="parames.reviewer"
          size="small"
          clearable
          placeholder="搜索审批人姓名"
        ></el-input>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-col>
    </el-row>
    <el-row class="main-box channel1234" style="margin:10px -5px;">
      <el-col :span="24">
        <el-table
          :data="tableData"
          border
          :row-class-name="tableRowClassName"
          v-loading="loading"
          style="margin-top:14px;"
        >
          <el-table-column min-width="120" prop="reviewer" label="审批人">
            <template slot-scope="scope">
              <div>{{scope.row.reviewer}}</div>
            </template>
          </el-table-column>
          <el-table-column min-width="120" prop="refundPerson" label="退款人">
            <template slot-scope="scope">
              <div>{{scope.row.refundPerson}}</div>
            </template>
          </el-table-column>
          <el-table-column min-width="100" prop="customerName" label="客户名称"></el-table-column>
          <el-table-column min-width="100" prop="refundAmount" label="退款金额"></el-table-column>
          <el-table-column min-width="120" prop="refundReason" label="撤户原因"></el-table-column>
          <el-table-column min-width="130" prop="refundDate" label="退款日期">
            <template slot-scope="scope">
              <span>{{scope.row.refundDate | formatDate}}</span>
            </template>
          </el-table-column>
          <el-table-column min-width="130" prop="receiptStartDate" label="缴费起始日期">
            <template slot-scope="scope">
              <span>{{scope.row.receiptStartDate | formatDate}}</span>
            </template>
          </el-table-column>
          <el-table-column min-width="130" prop="receiptEndDate" label="缴费截止日期">
            <template slot-scope="scope">
              <span>{{scope.row.receiptEndDate | formatDate}}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="24">
        <pages :parames="parames" @render="checkPage"></pages>
      </el-col>
    </el-row>
    <contractDetailDialog :detailData="detailData" @checkRender="getList"></contractDetailDialog>

  </div>
</template>

<script>
import contractDetailDialog from "../contractManage/contractDetailDialog.vue"; //合同详情弹窗

export default {
  data() {
    return {
      loading: false,
      parames: {
        page: 1, //页码index
        limit: 10, //页码最大
        reviewer: '', //联系人名称
        totalCount: 0,
        search: []
      },
      imgData: {
        name: '',
        url: '',
        show: false,
      },
      detailData: { //合同详情弹窗
        id: '',
        show: false
      },
      dialogData: {
        //新建弹窗
        type: '',
        title: '',
        show: false
      },
      tableData: [],
      shenheBtn: false
    };
  },
  components: {
    contractDetailDialog
  },
  methods: {
    search() {
      //查询
      this.parames.page = 1;
      let searchDate = this.parames.search
      let n = 0
      this.parames.search.forEach(el=>{
        if (el.key == 'reviewer') {
          n = 1
        }
      })
      if (this.parames.reviewer && n == 0) {
        this.parames.search.push({
          key: 'reviewer',
          value: this.parames.reviewer,
          type: 'string'
        })
      } else if (this.parames.reviewer && n == 1) {
        this.parames.search.forEach((el,index)=>{
          if (el.key == 'reviewer') {
            el.value = this.parames.reviewer
          }
        })
      } else if (!this.parames.reviewer && n == 1) {
        this.parames.search.forEach((el,index)=>{
          if (el.key == 'reviewer') {
            this.parames.search.splice(index,1)
          }
        })
      }
      let b = 0
      this.parames.search.forEach(el=>{
        if (el.key == 'reviewStatus') {
          b = 1
        }
      })
      if (this.parames.reviewStatus && b == 0) {
        this.parames.search.push({
          key: 'reviewStatus',
          value: this.parames.reviewStatus,
          type: 'enumeration'
        })
      } else if (this.parames.reviewStatus && b == 1) {
        this.parames.search.forEach((el,index)=>{
          if (el.key == 'reviewStatus') {
            el.value = this.parames.reviewStatus
          }
        })
      } else if (!this.parames.reviewStatus && b == 1) {
        this.parames.search.forEach((el,index)=>{
          if (el.key == 'reviewStatus') {
            this.parames.search.splice(index,1)
          }
        })
      }
      this.getList()
    },
    handleSearch() {
      //打开高级搜索弹窗
      this.searchData.customerName = this.parames.customerName
      this.searchData.show = true;
    },
    checkSearch (value) {
      this.parames.search = value
      value.forEach(el=>{
        if(el.key == 'reviewer') {
          this.parames.reviewer = el.value
        }
      })
      this.parames.page = 1
      this.getList()
    },
    checkPage () {
      this.getList()
    },
    getList() {//获取页面数据
      this.loading = true
      this.$post(this.$api.postFinanceRefundRevokeList,this.parames).then(response => {
        if (response.data.succeed) {
          this.parames.totalCount = response.data.totalCount
          this.tableData = response.data.data.data
        }
        setTimeout(() => {
          this.loading = false
        }, 200);
      })
    },
    tableRowClassName({ row, rowIndex }) {
      //斑马表格
      if (rowIndex % 2 === 1) {
        return "warning-row";
      } else {
        return "success-row";
      }
      return "";
    }
  },
  mounted() {
    this.getList()
  }
};
</script>

<style>
.el-table .warning-row {
  background: #f9f9f9;
}
.el-table .success-row {
  background: #fff;
}
</style>